NOTE
Leader Election with ZooKeeper
A ZooKeeper recipe for application leader election using ephemeral sequential nodes and predecessor watches.
This is a historical learning note and may contain outdated or incomplete understanding.
A common application leader-election recipe creates ephemeral sequential znodes under an election path. The participant owning the smallest sequence number becomes leader; others watch the immediately preceding node rather than all watching the leader.
When the predecessor disappears, a participant re-checks ordering and may become leader. Ephemeral nodes disappear when the ZooKeeper session expires, enabling failover.
Election alone does not prevent a previously isolated leader from continuing external side effects. Critical resources should use epochs/fencing tokens or another mechanism that rejects stale leaders.